package com.tongzhou.tongzhou.account.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.account.dao.IDefaultCallDAO;
import com.tongzhou.tongzhou.account.model.DefaultCall;
import com.tongzhou.tongzhou.account.model.SearchDefaultCallCondition;

public class DefaultCallAction extends ActionSupport{
	private int id;
	private DefaultCall DefaultCall;
	private List<DefaultCall> result=null;
	private SearchDefaultCallCondition condition=null;
	
	private int pageSize ;
	private int currentPage ;
	private String orderBy ;
	private String orderByType ;
	
	private IDefaultCallDAO dao=null;
	/**
	 * 默认联系方式列表界面
	 *@author: 彭定雄
	 *@return 
	 *@throws DBException
	 */
	public String listDefaultCall() throws DBException{
		checkSearchCondition();
		condition = new SearchDefaultCallCondition();
		if (currentPage == 0){
			currentPage = 1;
		}
		condition.setCurrentPage(currentPage) ;
		condition.setOrderBy(orderBy);
		condition.setOrderByType(orderByType) ;
		condition.setPageSize(pageSize) ;
	    result = dao.listDefaultCall(condition);
		return "listDefaultCall";
	} 
	
	
	/**
	 * 设置列表显示格式
	 *@author: 彭定雄
	 */
	private void checkSearchCondition(){
		if(currentPage <=0){
			currentPage = 1 ;
		}
		
		if(pageSize<=0){
			pageSize = 10 ;
		}
		
		if(orderBy==null||"".equals(orderBy)){
			orderBy = "id" ;
		}
		
		if(orderByType == null || "".equals(orderByType)){
			orderByType = "desc" ;
		}
	}
	
	/**
	 * 新增默认联系方式
	 *@author: 彭定雄
	 *@return
	 *@throws DBException
	 */
	public String toAddDefaultCall() throws DBException{
		return "addDefaultCall";
	}
	
	public String addDefaultCall() throws DBException{
		dao.addDefaultCall(DefaultCall);
		listDefaultCall();
		return "listDefaultCall";
	}
	
	public String deleteDefaultCall() throws DBException{
		dao.deleteDefaultCall(id);
		listDefaultCall();
		return "listDefaultCall";
	}
	
	public String toEditDefaultCall() throws DBException{
		DefaultCall=dao.getDefaultCallById(id);
		return "editDefaultCall";
	}
	
	public String editDefaultCall() throws DBException{
		dao.updateDefaultCall(DefaultCall);
		listDefaultCall();
		return "listDefaultCall";
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public List<DefaultCall> getResult() {
		return result;
	}


	public void setResult(List<DefaultCall> result) {
		this.result = result;
	}

	public SearchDefaultCallCondition getCondition() {
		return condition;
	}


	public void setCondition(SearchDefaultCallCondition condition) {
		this.condition = condition;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}


	public String getOrderBy() {
		return orderBy;
	}


	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}


	public String getOrderByType() {
		return orderByType;
	}


	public void setOrderByType(String orderByType) {
		this.orderByType = orderByType;
	}


	public IDefaultCallDAO getDao() {
		return dao;
	}


	public void setDao(IDefaultCallDAO dao) {
		this.dao = dao;
	}


	public DefaultCall getDefaultCall() {
		return DefaultCall;
	}


	public void setDefaultCall(DefaultCall DefaultCall) {
		this.DefaultCall = DefaultCall;
	}
	
}
